/*
 * Copyright (c) 2016 咖枯 <kaku201313@163.com | 3772304@qq.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package android07.newtop.fragment;

import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.support.v4.widget.NestedScrollView;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.jude.beam.bijection.RequiresPresenter;
import com.jude.beam.expansion.data.BeamDataFragment;

import java.io.ByteArrayInputStream;
import java.util.Calendar;
import java.util.List;

import android07.newtop.R;
import android07.newtop.activity.WeatherActivity;
import android07.newtop.app.WeacConstants;
import android07.newtop.model.bean.WeatherInfoBean;
import android07.newtop.presenter.WeaFragmentPresenter;
import android07.newtop.presenter.WeatherFragmentPresenter;
import android07.newtop.utils.LogUtil;
import android07.newtop.utils.MyUtil;
import android07.newtop.view.LineChartViewDouble;
import android07.newtop.view.RichDrawableText;

/**
 * 天气Fragment，使用Beam框架开发
 */
@RequiresPresenter(WeaFragmentPresenter.class)
public class WeaFragment extends BeamDataFragment<WeaFragmentPresenter, WeatherInfoBean> {
    /**
     * Log tag ：WeaFragment
     */
    private static final String LOG_TAG = "WeaFragment";

    /**
     * 天气的requestCode
     */
    private static final int REQUEST_WEA = 1;
    private static final String TAG = WeaFragment.class.getSimpleName();

    /**
     * 城市名
     */
    // private TextView mCityNameTv;

    /**
     * 警报
     */
    private TextView mAlarmTv;

    /**
     * 更新时间
     */
    private TextView mUpdateTimeTv;


    /**
     * 温度1
     */
    private ImageView mTemperature1Iv;

    /**
     * 温度2
     */
    private ImageView mTemperature2Iv;

    /**
     * 温度3
     */
    private ImageView mTemperature3Iv;

    /**
     * 天气类型
     */
    private TextView mWeatherTypeTv;


    /**
     * 大气环境
     */
    private RichDrawableText mAqiTv;

    /**
     * 湿度
     */
    private RichDrawableText mHumidityTv;

    /**
     * 风向、风力
     */
    private RichDrawableText mWindTv;


    /**
     * 今天天气类型图片
     */
    private ImageView mWeatherTypeIvToday;

    /**
     * 今天高温
     */
    private TextView mTempHighTvToday;

    /**
     * 今天低温
     */
    private TextView mTempLowTvToday;

    /**
     * 今天天气类型文字
     */
    private TextView mWeatherTypeTvToday;


    /**
     * 明天天气类型图片
     */
    private ImageView mWeatherTypeIvTomorrow;

    /**
     * 明天高温
     */
    private TextView mTempHighTvTomorrow;

    /**
     * 明天低温
     */
    private TextView mTempLowTvTomorrow;

    /**
     * 明天天气类型文字
     */
    private TextView mWeatherTypeTvTomorrow;


    /**
     * 后天天气类型图片
     */
    private ImageView mWeatherTypeIvDayAfterTomorrow;

    /**
     * 后天高温
     */
    private TextView mTempHighTvDayAfterTomorrow;

    /**
     * 后天低温
     */
    private TextView mTempLowTvDayAfterTomorrow;

    /**
     * 后天天气类型文字
     */
    private TextView mWeatherTypeTvDayAfterTomorrow;


    /**
     * 多天预报标题2
     */
    private TextView mDaysForecastTvWeek2;

    /**
     * 多天预报标题3
     */
    private TextView mDaysForecastTvWeek3;

    /**
     * 多天预报标题4
     */
    private TextView mDaysForecastTvWeek4;

    /**
     * 多天预报标题5
     */
    private TextView mDaysForecastTvWeek5;

    /**
     * 多天预报标题6
     */
    private TextView mDaysForecastTvWeek6;


    /**
     * 多天预报日期2
     */
    private TextView mDaysForecastTvDay2;

    /**
     * 多天预报日期3
     */
    private TextView mDaysForecastTvDay3;

    /**
     * 多天预报日期4
     */
    private TextView mDaysForecastTvDay4;

    /**
     * 多天预报日期5
     */
    private TextView mDaysForecastTvDay5;

    /**
     * 多天预报日期6
     */
    private TextView mDaysForecastTvDay6;


    /**
     * 多天预报白天天气类型图片2
     */
    private ImageView mDaysForecastWeaTypeDayIv2;

    /**
     * 多天预报白天天气类型图片3
     */
    private ImageView mDaysForecastWeaTypeDayIv3;

    /**
     * 多天预报白天天气类型图片4
     */
    private ImageView mDaysForecastWeaTypeDayIv4;

    /**
     * 多天预报白天天气类型图片5
     */
    private ImageView mDaysForecastWeaTypeDayIv5;

    /**
     * 多天预报白天天气类型图片6
     */
    private ImageView mDaysForecastWeaTypeDayIv6;


    /**
     * 多天预报白天天气类型文字2
     */
    private TextView mDaysForecastWeaTypeDayTv2;

    /**
     * 多天预报白天天气类型文字3
     */
    private TextView mDaysForecastWeaTypeDayTv3;

    /**
     * 多天预报白天天气类型文字4
     */
    private TextView mDaysForecastWeaTypeDayTv4;

    /**
     * 多天预报白天天气类型文字5
     */
    private TextView mDaysForecastWeaTypeDayTv5;

    /**
     * 多天预报白天天气类型文字6
     */
    private TextView mDaysForecastWeaTypeDayTv6;


    /**
     * 温度曲线
     */
    private LineChartViewDouble mCharView;


    /**
     * 多天预报夜间天气类型图片2
     */
    private ImageView mDaysForecastWeaTypeNightIv2;

    /**
     * 多天预报夜间天气类型图片3
     */
    private ImageView mDaysForecastWeaTypeNightIv3;

    /**
     * 多天预报夜间天气类型图片4
     */
    private ImageView mDaysForecastWeaTypeNightIv4;

    /**
     * 多天预报夜间天气类型图片5
     */
    private ImageView mDaysForecastWeaTypeNightIv5;

    /**
     * 多天预报夜间天气类型图片6
     */
    private ImageView mDaysForecastWeaTypeNightIv6;


    /**
     * 多天预报夜间天气类型文字2
     */
    private TextView mDaysForecastWeaTypeNightTv2;

    /**
     * 多天预报夜间天气类型文字3
     */
    private TextView mDaysForecastWeaTypeNightTv3;

    /**
     * 多天预报夜间天气类型文字4
     */
    private TextView mDaysForecastWeaTypeNightTv4;

    /**
     * 多天预报夜间天气类型文字5
     */
    private TextView mDaysForecastWeaTypeNightTv5;

    /**
     * 多天预报夜间天气类型文字6
     */
    private TextView mDaysForecastWeaTypeNightTv6;


    /**
     * 多天预报风向2
     */
    private TextView mDaysForecastWindDirectionTv2;

    /**
     * 多天预报风向3
     */
    private TextView mDaysForecastWindDirectionTv3;

    /**
     * 多天预报风向4
     */
    private TextView mDaysForecastWindDirectionTv4;

    /**
     * 多天预报风向5
     */
    private TextView mDaysForecastWindDirectionTv5;

    /**
     * 多天预报风向6
     */
    private TextView mDaysForecastWindDirectionTv6;


    /**
     * 多天预报风力2
     */
    private TextView mDaysForecastWindPowerTv2;

    /**
     * 多天预报风力3
     */
    private TextView mDaysForecastWindPowerTv3;

    /**
     * 多天预报风力4
     */
    private TextView mDaysForecastWindPowerTv4;

    /**
     * 多天预报风力5
     */
    private TextView mDaysForecastWindPowerTv5;

    /**
     * 多天预报风力6
     */
    private TextView mDaysForecastWindPowerTv6;


    /**
     * 雨伞指数TextView
     */
    private TextView mLifeIndexUmbrellaTv;

    /**
     * 紫外线指数TextView
     */
    private TextView mLifeIndexUltravioletRaysTv;

    /**
     * 穿衣指数TextView
     */
    private TextView mLifeIndexDressTv;

    /**
     * 感冒指数TextView
     */
    private TextView mLifeIndexColdTv;

    /**
     * 晨练指数TextView
     */
    private TextView mLifeIndexMorningExerciseTv;

    /**
     * 运动指数TextView
     */
    private TextView mLifeIndexSportTv;

    /**
     * 洗车指数TextView
     */
    private TextView mLifeIndexCarWashTv;

    /**
     * 晾晒指数TextView
     */
    private TextView mLifeIndexAirCureTv;


    /**
     * 雨伞指数详细
     */
    private String mLifeIndexUmbrellaDetail;

    /**
     * 紫外线指数详细
     */
    private String mLifeIndexUltravioletRaysDetail;

    /**
     * 穿衣指数详细
     */
    private String mLifeIndexDressDetail;

    /**
     * 感冒指数详细
     */
    private String mLifeIndexColdDetail;

    /**
     * 晨练指数详细
     */
    private String mLifeIndexMorningExerciseDetail;

    /**
     * 运动指数详细
     */
    private String mLifeIndexSportDetail;

    /**
     * 洗车指数详细
     */
    private String mLifeIndexCarWashDetail;

    /**
     * 晾晒指数详细
     */
    private String mLifeIndexAirCureDetail;


    /**
     * 刷新按钮
     */
    public ImageView mRefreshBtn;

    /**
     * 延迟刷新线程是否已经启动
     */
    public boolean mIsPostDelayed;

    /**
     * 延迟刷新Handler
     */
    public Handler mHandler;

    /**
     * 延迟刷新Runnable
     */
    public Runnable mRun;

    /**
     * 标志位，标志已经初始化完成
     */
    private boolean mIsPrepared;

    /**
     * 上次主动更新时间
     */
    private long mLastActiveUpdateTime;

    /**
     * 设置壁纸
     */
    private LinearLayout mBackGround;

    /**
     * 模糊处理过的Drawable
     */
    private Drawable mBlurDrawable;

    /**
     * 屏幕密度
     */
    private float mDensity;

    /**
     * 透明
     */
    private int mAlpha = 0;

    /**
     * 当前天气预报城市名
     */
    private String mCityName;

    /**
     * 当前天气预报城市天气代码
     */
    private String mCityWeatherCode;


    /**
     * 首次打开天气界面
     */
    private boolean mIsFirstUse = false;

    /**
     * 是否立刻刷新
     */
    private boolean mIsPromptRefresh = true;

    /**
     * 是否自动定位过
     */
    private boolean mIsLocated = false;

    /**
     * 天气界面布局
     */
    private ViewGroup mWeatherGroup;

    /**
     * 加载中进度框
     */
    private ViewGroup mProgressBar;

    // private OnVisibleListener mOnVisibleListener;

    /**
     * 默认城市名
     */
    private String mDefaultCityName;

    /**
     * 默认城市天气代号
     */
    private String mDefaultCityWeatherCode;

    /**
     * 下拉刷新控件
     */
    public SwipeRefreshLayout swipeRefreshLayout;

    ViewStub viewStub;
    View view;
    boolean isinflate;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fm_wea, null);
        Log.d(TAG, "onCreateView: ");
        return view;
    }


    @Override
    public void setData(WeatherInfoBean data) {
        super.setData(data);
        //写在这里是为了，展示体验，不会卡顿
        //这里判断是为了一个ViewStub只inflate一次即可，重复inflate会报错
        if (!isinflate) {
            viewStub = (ViewStub) view.findViewById(R.id.viewstub_wea);
            viewStub.inflate();
            init(view);
            isinflate = true;
        }


        Log.d(TAG, "setData: ");
        initWeather(data.getResult().getData());
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        isinflate=false;
        Log.d(TAG, "onDestroyView: ");
    }

    /**
     * 初始化天气
     *
     * @param weatherInfo 天气信息类
     */
    @SuppressWarnings("deprecation")
    private void initWeather(final WeatherInfoBean.ResultBean.DataBean weatherInfo) {
        if (weatherInfo == null) {
            return;
        }
        // 多天预报信息
        List<WeatherInfoBean.ResultBean.DataBean.WeatherBean> weatherDaysForecasts = weatherInfo.getWeather();


        // 今天天气信息
        WeatherInfoBean.ResultBean.DataBean.WeatherBean weather2;
        // 明天天气信息
        WeatherInfoBean.ResultBean.DataBean.WeatherBean weather3;
        // 后天天气信息
        WeatherInfoBean.ResultBean.DataBean.WeatherBean weather4;
        // 第五天天天气信息
        WeatherInfoBean.ResultBean.DataBean.WeatherBean weather5;
        // 第六天天气信息
        WeatherInfoBean.ResultBean.DataBean.WeatherBean weather6;

        String time[] = weatherInfo.getRealtime().getTime().split(":");
        int hour1 = Integer.parseInt(time[0]);
        int minute1 = Integer.parseInt(time[1]);
        //更新时间从23：45开始到05：20以前的数据，后移一天填充
        if ((hour1 == 23 && minute1 >= 45) || (hour1 < 5) ||
                ((hour1 == 5) && (minute1 < 20))) {
            if (weatherDaysForecasts.size() >= 6) {

                weather2 = weatherDaysForecasts.get(2);
                weather3 = weatherDaysForecasts.get(3);
                weather4 = weatherDaysForecasts.get(4);
                weather5 = weatherDaysForecasts.get(5);
                weather6 = weatherDaysForecasts.get(5);
            } else {
                weather2 = weatherDaysForecasts.get(0);
                weather3 = weatherDaysForecasts.get(1);
                weather4 = weatherDaysForecasts.get(2);
                weather5 = weatherDaysForecasts.get(3);
                weather6 = weatherDaysForecasts.get(4);


            }
        } else {
            if (weatherDaysForecasts.size() >= 6) {
                weather2 = weatherDaysForecasts.get(1);
                weather3 = weatherDaysForecasts.get(2);
                weather4 = weatherDaysForecasts.get(3);
                weather5 = weatherDaysForecasts.get(4);
                weather6 = weatherDaysForecasts.get(5);
            } else {

                weather2 = weatherDaysForecasts.get(0);
                weather3 = weatherDaysForecasts.get(1);
                weather4 = weatherDaysForecasts.get(2);
                weather5 = weatherDaysForecasts.get(3);
                weather6 = weatherDaysForecasts.get(4);
            }
        }

        Calendar calendar = Calendar.getInstance();
        // 现在小时
        int hour = calendar.get(Calendar.HOUR_OF_DAY);

        // 设置城市名
//        setCityName(weatherInfo);
        // 设置预警信息
        setAlarmInfo(weatherInfo.getPm25());
        // 设置更新时间
        setUpdateTime(weatherInfo.getRealtime());
        // 设置温度
        setTemperature(weatherInfo.getRealtime());
        // 设置天气类型
        setWeatherType(weatherInfo.getRealtime(), hour);
        // 设置aqi
        setAQI(weatherInfo.getPm25().getPm25());
        // 设置湿度
        setHumidity(weatherInfo.getRealtime().getWeather());
        // 设置风向、风力
        setWind(weatherInfo.getRealtime().getWind());
        // 设置今天，明天，后天大概天气
        setThreeDaysWeather(weather2, weather3, weather4, hour);

        // 设置多天天气预报
        setDaysForecast(weather2, weather3, weather4, weather5, weather6,
                hour1, minute1, calendar);

        // 生活指数信息
        setLifeIndex(weatherInfo.getLife());


    }

    /**
     * 设置多天天气预报
     */
    private void setDaysForecast(WeatherInfoBean.ResultBean.DataBean.WeatherBean weather2,
                                 WeatherInfoBean.ResultBean.DataBean.WeatherBean weather3,
                                 WeatherInfoBean.ResultBean.DataBean.WeatherBean weather4,
                                 WeatherInfoBean.ResultBean.DataBean.WeatherBean weather5,
                                 WeatherInfoBean.ResultBean.DataBean.WeatherBean weather6,
                                 int hour1,
                                 int minute1,
                                 Calendar calendar) {
        // 日期和星期标题 【索引0：日期;索引1：星期】

        String[] day2;
        String[] day3;
        String[] day4;
        String[] day5;
        String[] day6;
        if ((hour1 == 23 && minute1 >= 45) || (hour1 < 5) || ((hour1 == 5) && (minute1 < 20))) {
            if (weather2 != null) {
                day2 = getDay(weather2);
            } else {
                day2 = null;
            }

            assert weather2 != null;

            day3 = getDay(weather3);
            day4 = getDay(weather4);
            day5 = getDay(weather5);
            day6 = getDay(weather6);
        } else {
            if (weather2 != null) {
                day2 = getDay(weather2);
            } else {
                day2 = null;
            }

            assert weather2 != null;
            day3 = getDay(weather3);
            day4 = getDay(weather4);
            day5 = getDay(weather5);
            day6 = getDay(weather6);
        }

        // 设置标题星期
        mDaysForecastTvWeek2.setText(getString(R.string.today));
        mDaysForecastTvWeek3.setText(day3[1]);
        mDaysForecastTvWeek4.setText(day4[1]);
        mDaysForecastTvWeek5.setText(day5[1]);
        mDaysForecastTvWeek6.setText(day6[1]);


        // 设置日期

        mDaysForecastTvDay2.setText(day2[0]);
        mDaysForecastTvDay3.setText(day3[0]);
        mDaysForecastTvDay4.setText(day4[0]);
        mDaysForecastTvDay5.setText(day5[0]);
        mDaysForecastTvDay6.setText(day6[0]);

        // 取得白天天气类型图片id

        int weatherDayId2 = MyUtil.getWeatherTypeImageID(weather2.getInfo().getDay().get(1), true);
        int weatherDayId3 = MyUtil.getWeatherTypeImageID(weather3.getInfo().getDay().get(1), true);
        int weatherDayId4 = MyUtil.getWeatherTypeImageID(weather4.getInfo().getDay().get(1), true);
        int weatherDayId5 = MyUtil.getWeatherTypeImageID(weather5.getInfo().getDay().get(1), true);
        int weatherDayId6 = MyUtil.getWeatherTypeImageID(weather6.getInfo().getDay().get(1), true);

        //设置白天天气类型图片
//        mDaysForecastWeaTypeDayIv1.setImageResource(weatherDayId1);
        mDaysForecastWeaTypeDayIv2.setImageResource(weatherDayId2);
        mDaysForecastWeaTypeDayIv3.setImageResource(weatherDayId3);
        mDaysForecastWeaTypeDayIv4.setImageResource(weatherDayId4);
        mDaysForecastWeaTypeDayIv5.setImageResource(weatherDayId5);
        mDaysForecastWeaTypeDayIv6.setImageResource(weatherDayId6);

        // 设置白天天气类型文字
        if (weather2 != null) {
            mDaysForecastWeaTypeDayTv2.setText(weather2.getInfo().getDay().get(1));
        } else {
            mDaysForecastWeaTypeDayTv2.setText(R.string.dash);
        }

        mDaysForecastWeaTypeDayTv3.setText(weather3.getInfo().getDay().get(1));
        mDaysForecastWeaTypeDayTv4.setText(weather4.getInfo().getDay().get(1));
        mDaysForecastWeaTypeDayTv5.setText(weather5.getInfo().getDay().get(1));
        mDaysForecastWeaTypeDayTv6.setText(weather6.getInfo().getDay().get(1));

        // 设置白天温度曲线
        if (weather2 != null) {
            mCharView.setTempDay(new int[]{
                    getTemp(weather2.getInfo().getDay().get(2)),
                    getTemp(weather3.getInfo().getDay().get(2)),
                    getTemp(weather4.getInfo().getDay().get(2)),
                    getTemp(weather5.getInfo().getDay().get(2)),
                    getTemp(weather6.getInfo().getDay().get(2))});
        }
        // 设置夜间温度曲线
        if (weather2 != null) {
            mCharView.setTempNight(new int[]{
                    getTemp(weather2.getInfo().getNight().get(2)),
                    getTemp(weather3.getInfo().getNight().get(2)),
                    getTemp(weather4.getInfo().getNight().get(2)),
                    getTemp(weather5.getInfo().getNight().get(2)),
                    getTemp(weather6.getInfo().getNight().get(2))});
        }

        mCharView.invalidate();

        // 设置夜间天气类型文字
        if (weather2 != null) {
            mDaysForecastWeaTypeNightTv2.setText(weather2.getInfo().getNight().get(1));
        } else {
            mDaysForecastWeaTypeNightTv2.setText(R.string.dash);
        }
        mDaysForecastWeaTypeNightTv3.setText(weather3.getInfo().getNight().get(1));
        mDaysForecastWeaTypeNightTv4.setText(weather4.getInfo().getNight().get(1));
        mDaysForecastWeaTypeNightTv5.setText(weather5.getInfo().getNight().get(1));
        mDaysForecastWeaTypeNightTv6.setText(weather6.getInfo().getNight().get(1));


        // 取得夜间天气类型图片id
        int weatherNightId2;
        if (weather2 != null) {
            weatherNightId2 = MyUtil.getWeatherTypeImageID(weather2.getInfo().getNight().get(1), false);
        } else {
            weatherNightId2 = R.drawable.ic_weather_no;
        }
        int weatherNightId3 = MyUtil.getWeatherTypeImageID(weather3.getInfo().getNight().get(1), false);
        int weatherNightId4 = MyUtil.getWeatherTypeImageID(weather4.getInfo().getNight().get(1), false);
        int weatherNightId5 = MyUtil.getWeatherTypeImageID(weather5.getInfo().getNight().get(1), false);
        int weatherNightId6 = MyUtil.getWeatherTypeImageID(weather6.getInfo().getNight().get(1), false);

        //设置夜间天气类型图片
        mDaysForecastWeaTypeNightIv2.setImageResource(weatherNightId2);
        mDaysForecastWeaTypeNightIv3.setImageResource(weatherNightId3);
        mDaysForecastWeaTypeNightIv4.setImageResource(weatherNightId4);
        mDaysForecastWeaTypeNightIv5.setImageResource(weatherNightId5);
        mDaysForecastWeaTypeNightIv6.setImageResource(weatherNightId6);

        // 设置风向
        if (weather2 != null) {
            mDaysForecastWindDirectionTv2.setText(weather2.getInfo().getNight().get(3));
        } else {
            mDaysForecastWindDirectionTv2.setText(R.string.dash);
        }

        mDaysForecastWindDirectionTv3.setText(weather3.getInfo().getNight().get(3));
        mDaysForecastWindDirectionTv4.setText(weather4.getInfo().getNight().get(3));
        mDaysForecastWindDirectionTv5.setText(weather5.getInfo().getNight().get(3));
        mDaysForecastWindDirectionTv6.setText(weather6.getInfo().getNight().get(3));

        // 设置风力
        if (weather2 != null) {
            mDaysForecastWindPowerTv2.setText(weather2.getInfo().getNight().get(4));
        } else {
            mDaysForecastWindPowerTv2.setText(R.string.dash);
        }
        mDaysForecastWindPowerTv2.setText(weather2.getInfo().getNight().get(4));
        mDaysForecastWindPowerTv3.setText(weather3.getInfo().getNight().get(4));
        mDaysForecastWindPowerTv4.setText(weather4.getInfo().getNight().get(4));
        mDaysForecastWindPowerTv5.setText(weather5.getInfo().getNight().get(4));
        mDaysForecastWindPowerTv6.setText(weather6.getInfo().getNight().get(4));
    }


    /**
     * 设置今天，明天，后天大概天气
     *
     * @param weather2 今天
     * @param weather3 明天
     * @param weather4 后天
     * @param hour     当前小时
     */
    private void setThreeDaysWeather(WeatherInfoBean.ResultBean.DataBean.WeatherBean weather2, WeatherInfoBean.ResultBean.DataBean.WeatherBean weather3,
                                     WeatherInfoBean.ResultBean.DataBean.WeatherBean weather4, int hour) {
        // 天气类型图片id
        int weatherId;

        // 设置今天天气信息
        // 当前为凌晨
        if (hour >= 0 && hour < 6) {
            weatherId = MyUtil.getWeatherTypeImageID(weather2.getInfo().getDay().get(1), false);
            // 当前为白天时
        } else if (hour >= 6 && hour < 18) {
            weatherId = MyUtil.getWeatherTypeImageID(weather2.getInfo().getNight().get(1), true);
            // 当前为夜间
        } else {
            weatherId = MyUtil.getWeatherTypeImageID(weather2.getInfo().getNight().get(1), false);
        }
        mWeatherTypeIvToday.setImageResource(weatherId);
        mTempHighTvToday.setText(String.format(getString(R.string.temp_value)
                , weather2.getInfo().getDay().get(2)));
        mTempLowTvToday.setText(String.format(getString(R.string.temp_value)
                , weather2.getInfo().getNight().get(2)));
        mWeatherTypeTvToday.setText(MyUtil.getWeatherType
                (getActivity(), weather2.getInfo().getDay().get(1), weather2.getInfo().getNight().get(1)));

        // 设置明天天气信息
        weatherId = MyUtil.getWeatherTypeImageID(weather3.getInfo().getNight().get(1), true);
        mWeatherTypeIvTomorrow.setImageResource(weatherId);
        ;
        mTempHighTvTomorrow.setText(String.format(getString(R.string.temp_value)
                , weather3.getInfo().getDay().get(2)));
        mTempLowTvTomorrow.setText(String.format(getString(R.string.temp_value)
                , weather3.getInfo().getNight().get(2)));
        mWeatherTypeTvTomorrow.setText(MyUtil.getWeatherType
                (getActivity(), weather3.getInfo().getDay().get(1), weather3.getInfo().getNight().get(1)));

        // 设置后天天气信息
        weatherId = MyUtil.getWeatherTypeImageID(weather4.getInfo().getDay().get(1), true);
        mWeatherTypeIvDayAfterTomorrow.setImageResource(weatherId);


        mTempHighTvDayAfterTomorrow.setText(String.format(getString(R.string.temp_value)
                , weather4.getInfo().getDay().get(2)));
        mTempLowTvDayAfterTomorrow.setText(String.format(getString(R.string.temp_value)
                , weather4.getInfo().getNight().get(2)));
        mWeatherTypeTvDayAfterTomorrow.setText(MyUtil.getWeatherType
                (getActivity(), weather4.getInfo().getDay().get(1), weather4.getInfo().getNight().get(1)));
    }

    /**
     * 设置风向、风力
     */
    private void setWind(WeatherInfoBean.ResultBean.DataBean.RealtimeBean.WindBean windBean) {
        if (windBean.getDirect() != null && windBean.getPower() != null) {
            // 设置风向图片
            setImage(mWindTv, getWindImageId(windBean.getDirect()));
            // 设置风向、风力
            mWindTv.setText(String.format(getString(R.string.aqi)
                    , windBean.getDirect(), windBean.getPower()));
        } else {
            setImage(mWindTv, R.drawable.weather_ic_wind_3);
            mWindTv.setText(R.string.no);
        }
    }

    /**
     * 设置湿度
     */
    private void setHumidity(WeatherInfoBean.ResultBean.DataBean.RealtimeBean.WeatherBean weatherBean) {
        if (weatherBean.getHumidity() != null) {
            // 设置湿度图片
//            setImage(mHumidityTv, getHumidityImageId(weatherInfo.getHumidity()));
            // 设置湿度
            mHumidityTv.setText(String.format(getString(R.string.humidity),
                    weatherBean.getHumidity()));
        } else {
//            setImage(mHumidityTv, R.drawable.ic_humidity20);
            mHumidityTv.setText(R.string.no);
        }
    }

    /**
     * 设置aqi
     */
    private void setAQI(WeatherInfoBean.ResultBean.DataBean.Pm25Bean.PmBean pmBean) {
        if (pmBean.getQuality() != null && pmBean.getCurPm() != null) {
            mAqiTv.setVisibility(View.VISIBLE);
            // 设置空气质量图片
            setImage(mAqiTv, getQualityImageId(pmBean.getQuality()));
            // 设置空气质量
            mAqiTv.setText(String.format(getString(R.string.aqi),
                    pmBean.getQuality(), pmBean.getCurPm()));
        } else {
            mAqiTv.setVisibility(View.GONE);
        }
    }
//

    /**
     * 设置天气类型
     *
     * @param weatherToday 今天天气信息
     * @param hour         当前小时
     */
    private void setWeatherType(WeatherInfoBean.ResultBean.DataBean.RealtimeBean weatherToday, int hour) {
        if (hour < 18) {
            // 白天天气
            mWeatherTypeTv.setText(weatherToday.getWeather().getInfo());
        } else {
            // 夜间天气
            mWeatherTypeTv.setText(weatherToday.getWeather().getInfo());
        }
    }
//

    /**
     * 设置温度
     *
     * @param weatherInfo weatherInfo
     */
    private void setTemperature(WeatherInfoBean.ResultBean.DataBean.RealtimeBean weatherInfo) {
        String temp = weatherInfo.getWeather().getTemperature();
        mTemperature1Iv.setVisibility(View.VISIBLE);
        mTemperature2Iv.setVisibility(View.VISIBLE);
        mTemperature3Iv.setVisibility(View.VISIBLE);
        if (temp != null) {
            // 两位正数
            if (temp.length() == 2 && !temp.contains("-")) {
                int temp1 = Integer.parseInt(temp.substring(0, 1));
                setTemperatureImage(temp1, mTemperature1Iv);
                int temp2 = Integer.parseInt(temp.substring(1));
                setTemperatureImage(temp2, mTemperature2Iv);
                mTemperature3Iv.setVisibility(View.GONE);
                // 一位
            } else if (temp.length() == 1 && !temp.contains("-")) {
                int temp1 = Integer.parseInt(temp);
                setTemperatureImage(temp1, mTemperature1Iv);
                mTemperature2Iv.setVisibility(View.GONE);
                mTemperature3Iv.setVisibility(View.GONE);
                // 两位负数
            } else if (temp.length() == 2 && temp.contains("-")) {
                mTemperature1Iv.setImageResource(R.drawable.weather_ic_minus);
                int temp2 = Integer.parseInt(temp.substring(1));
                setTemperatureImage(temp2, mTemperature2Iv);
                mTemperature3Iv.setVisibility(View.GONE);
                // 三位负数
            } else if (temp.length() == 3 && temp.contains("-")) {
                mTemperature1Iv.setImageResource(R.drawable.weather_ic_minus);
                int temp2 = Integer.parseInt(temp.substring(1, 2));
                setTemperatureImage(temp2, mTemperature2Iv);
                int temp3 = Integer.parseInt(temp.substring(2));
                setTemperatureImage(temp3, mTemperature3Iv);
            } else {
                mTemperature1Iv.setImageResource(R.drawable.weather_number_0);
                mTemperature2Iv.setImageResource(R.drawable.weather_number_0);
                mTemperature3Iv.setImageResource(R.drawable.weather_number_0);
            }
        } else {
            mTemperature1Iv.setImageResource(R.drawable.weather_number_0);
            mTemperature2Iv.setImageResource(R.drawable.weather_number_0);
            mTemperature3Iv.setImageResource(R.drawable.weather_number_0);
        }
    }
//

    /**
     * 设置更新时间
     *
     * @param realtimeBean weatherInfo
     */
    @SuppressWarnings("deprecation")
    private void setUpdateTime(WeatherInfoBean.ResultBean.DataBean.RealtimeBean realtimeBean) {
        if (realtimeBean.getTime() != null) {
            long now = System.currentTimeMillis();
            SharedPreferences share = getActivity().getSharedPreferences(
                    WeacConstants.BASE64, Activity.MODE_PRIVATE);
            // 最近一次天气更新时间
            long lastTime = share.getLong(getString(R.string.city_weather_update_time,
                    realtimeBean.getCity_name()), 0);
            // 更新间隔时间（小时）
            long minuteD = (now - lastTime) / 1000 / 60 / 60;
            // 更新时间
            String updateTime;
            if (minuteD < 24) {
                updateTime = String.format(getString(R.string.update_time), realtimeBean.getTime());
            } else if (minuteD >= 24 && minuteD < 48) {
                updateTime = String.format(getString(R.string.update_time2), realtimeBean.getTime());
            } else if (minuteD >= 48 && minuteD < 72) {
                updateTime = String.format(getString(R.string.update_time3), realtimeBean.getTime());
            } else if (minuteD >= 72 && minuteD < 96) {
                updateTime = String.format(getString(R.string.update_time4), 3);
            } else if (minuteD >= 96 && minuteD < 120) {
                updateTime = String.format(getString(R.string.update_time4), 4);
            } else if (minuteD >= 120 && minuteD < 144) {
                updateTime = String.format(getString(R.string.update_time4), 5);
            } else if (minuteD >= 144 && minuteD < 168) {
                updateTime = String.format(getString(R.string.update_time4), 6);
            } else {
                updateTime = getString(R.string.data_void);
            }
            mUpdateTimeTv.setText(realtimeBean.getTime());
            // 当不是数据过期
            if (!updateTime.equals(getString(R.string.data_void))) {
                mUpdateTimeTv.setTextColor(getResources().getColor(R.color.alpha_60_white));
            } else {
                mUpdateTimeTv.setTextColor(getResources().getColor(R.color.red));
            }
        } else {
            mUpdateTimeTv.setText(getString(R.string.dash));
            mUpdateTimeTv.setTextColor(getResources().getColor(R.color.alpha_60_white));
        }
    }

    /**
     * 设置P2.5信息
     *
     * @param pm25Bean weatherInfo
     */
    private void setAlarmInfo(final WeatherInfoBean.ResultBean.DataBean.Pm25Bean pm25Bean) {
        if (pm25Bean.getPm25() != null) {
            mAlarmTv.setVisibility(View.GONE);
            mAlarmTv.setText(pm25Bean.getPm25().getQuality());

        } else {
            mAlarmTv.setVisibility(View.GONE);
        }
    }

    /**
     * 取得风向图片id
     *
     * @param windDirection 风向
     * @return 风向图片id
     */
    private int getWindImageId(String windDirection) {
        int imgId;
        switch (windDirection) {
            case "南风":
                imgId = R.drawable.weather_ic_wind_1;
                break;
            case "西南风":
                imgId = R.drawable.weather_ic_wind_2;
                break;
            case "西风":
                imgId = R.drawable.weather_ic_wind_3;
                break;
            case "西北风":
                imgId = R.drawable.weather_ic_wind_4;
                break;
            case "北风":
                imgId = R.drawable.weather_ic_wind_5;
                break;
            case "东北风":
                imgId = R.drawable.weather_ic_wind_6;
                break;
            case "东风":
                imgId = R.drawable.weather_ic_wind_7;
                break;
            case "东南风":
                imgId = R.drawable.weather_ic_wind_8;
                break;
            default:
                imgId = R.drawable.weather_ic_wind_3;
                break;
        }
        return imgId;
    }


    /**
     * 设置左侧图片
     *
     * @param tv      textView
     * @param imageId 图片id
     */
    private void setImage(TextView tv, int imageId) {
        @SuppressWarnings("deprecation") Drawable drawable = getResources().getDrawable(imageId);
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getMinimumWidth(),
                    drawable.getMinimumHeight());
            // 设置图片
            tv.setCompoundDrawables(drawable, null, null, null);
        }
    }
//

    /**
     * 取得aqi图片id
     *
     * @param quality 大气质量
     * @return aqi图片id
     */
    private int getQualityImageId(String quality) {
        int imgId;
        switch (quality) {
            case "优":
                imgId = R.drawable.weather_ic_quality_nice;
                break;
            case "良":
                imgId = R.drawable.weather_ic_quality_good;
                break;
            case "轻度污染":
                imgId = R.drawable.weather_ic_quality_little;
                break;
            case "中度污染":
                imgId = R.drawable.weather_ic_quality_medium;
                break;
            case "重度污染":
                imgId = R.drawable.weather_ic_quality_serious;
                break;
            case "严重污染":
                imgId = R.drawable.weather_ic_quality_terrible;
                break;
            default:
                imgId = R.drawable.weather_ic_quality_nice;
                break;
        }
        return imgId;
    }

    /**
     * 设置生活指数
     *
     * @param
     */


    private void setLifeIndex(WeatherInfoBean.ResultBean.DataBean.LifeBean lifeBean) {

//        switch (index.getIndexName()) {
        //"雨伞指数":
//                mLifeIndexUmbrellaTv.setText(lifeBean.getInfo().get().get(0));
//                mLifeIndexUmbrellaDetail = index.getIndexDetail();
        //"紫外线强度":
        mLifeIndexUltravioletRaysTv.setText(lifeBean.getInfo().getZiwaixian().get(0));
        mLifeIndexUltravioletRaysDetail = lifeBean.getInfo().getZiwaixian().get(1);
        //"穿衣指数":
        mLifeIndexDressTv.setText(lifeBean.getInfo().getChuanyi().get(0));
        mLifeIndexDressDetail = lifeBean.getInfo().getChuanyi().get(1);
        // "感冒指数":
        mLifeIndexColdTv.setText(lifeBean.getInfo().getGanmao().get(0));
        mLifeIndexColdDetail = lifeBean.getInfo().getGanmao().get(1);
        //"晨练指数":
        mLifeIndexMorningExerciseTv.setText(lifeBean.getInfo().getKongtiao().get(0));
        mLifeIndexMorningExerciseDetail = lifeBean.getInfo().getKongtiao().get(1);
        // "运动指数":
        mLifeIndexSportTv.setText(lifeBean.getInfo().getYundong().get(0));
        mLifeIndexSportDetail = lifeBean.getInfo().getYundong().get(1);
        //"洗车指数":
        mLifeIndexCarWashTv.setText(lifeBean.getInfo().getXiche().get(0));
        mLifeIndexCarWashDetail = lifeBean.getInfo().getXiche().get(1);
//            // "晾晒指数":
//                mLifeIndexAirCureTv.setText(index.getIndexValue());
//                mLifeIndexAirCureDetail = index.getIndexDetail();

//        }
    }

    /**
     * 取得温度
     *
     * @param temp 温度信息
     * @return 温度
     */
    private int getTemp(String temp) {
        return Integer.parseInt(temp);
    }
//

    /**
     * 截取日期和星期
     *
     * @param date 日期信息
     * @return 包含日期和星期的数组
     */
    private String[] getDay(WeatherInfoBean.ResultBean.DataBean.WeatherBean date) {
        String[] date1 = new String[2];
        date1[0] = date.getDate();
        date1[1] = "周" + date.getWeek();
        return date1;
    }

    /**
     * 设置温度图片
     *
     * @param temp1     温度
     * @param imageView imageView控件
     */
    private void setTemperatureImage(int temp1, ImageView imageView) {
        switch (temp1) {
            case 0:
                imageView.setImageResource(R.drawable.weather_number_0);
                break;
            case 1:
                imageView.setImageResource(R.drawable.weather_number_1);
                break;
            case 2:
                imageView.setImageResource(R.drawable.weather_number_2);
                break;
            case 3:
                imageView.setImageResource(R.drawable.weather_number_3);
                break;
            case 4:
                imageView.setImageResource(R.drawable.weather_number_4);
                break;
            case 5:
                imageView.setImageResource(R.drawable.weather_number_5);
                break;
            case 6:
                imageView.setImageResource(R.drawable.weather_number_6);
                break;
            case 7:
                imageView.setImageResource(R.drawable.weather_number_7);
                break;
            case 8:
                imageView.setImageResource(R.drawable.weather_number_8);
                break;
            case 9:
                imageView.setImageResource(R.drawable.weather_number_9);
                break;
            default:
                imageView.setImageResource(R.drawable.weather_number_0);
                break;
        }
    }

    /**
     * 初始化控件
     *
     * @param view view
     */
    private void init(View view) {
        mWeatherGroup = (ViewGroup) view.findViewById(R.id.weather_layout);

        swipeRefreshLayout = (android.support.v4.widget.SwipeRefreshLayout) view.findViewById(R.id.sw_refresh);
        swipeRefreshLayout.setOnRefreshListener(getPresenter());

        mAlarmTv = (TextView) view.findViewById(R.id.alarm);
        mUpdateTimeTv = (TextView) view.findViewById(R.id.update_time);

        mTemperature1Iv = (ImageView) view.findViewById(R.id.temperature1);
        mTemperature2Iv = (ImageView) view.findViewById(R.id.temperature2);
        mTemperature3Iv = (ImageView) view.findViewById(R.id.temperature3);
        mWeatherTypeTv = (TextView) view.findViewById(R.id.weather_type);

        mAqiTv = (RichDrawableText) view.findViewById(R.id.aqi);
        mHumidityTv = (RichDrawableText) view.findViewById(R.id.humidity);
        mWindTv = (RichDrawableText) view.findViewById(R.id.wind);

        mWeatherTypeIvToday = (ImageView) view.findViewById(R.id.weather_type_iv_today);
        mWeatherTypeIvTomorrow = (ImageView) view.findViewById(R.id.weather_type_iv_tomorrow);
        mWeatherTypeIvDayAfterTomorrow = (ImageView) view.findViewById(R.id.weather_type_iv_day_after_tomorrow);

        mTempHighTvToday = (TextView) view.findViewById(R.id.temp_high_today);
        mTempHighTvTomorrow = (TextView) view.findViewById(R.id.temp_high_tomorrow);
        mTempHighTvDayAfterTomorrow = (TextView) view.findViewById(R.id.temp_high_day_after_tomorrow);

        mTempLowTvToday = (TextView) view.findViewById(R.id.temp_low_today);
        mTempLowTvTomorrow = (TextView) view.findViewById(R.id.temp_low_tomorrow);
        mTempLowTvDayAfterTomorrow = (TextView) view.findViewById(R.id.temp_low_day_after_tomorrow);

        mWeatherTypeTvToday = (TextView) view.findViewById(R.id.weather_type_tv_today);
        mWeatherTypeTvTomorrow = (TextView) view.findViewById(R.id.weather_type_tv_tomorrow);
        mWeatherTypeTvDayAfterTomorrow = (TextView) view.findViewById(R.id.weather_type_tv_day_after_tomorrow);

        mDaysForecastTvWeek2 = (TextView) view.findViewById(R.id.wea_days_forecast_week2);
        mDaysForecastTvWeek3 = (TextView) view.findViewById(R.id.wea_days_forecast_week3);
        mDaysForecastTvWeek4 = (TextView) view.findViewById(R.id.wea_days_forecast_week4);
        mDaysForecastTvWeek5 = (TextView) view.findViewById(R.id.wea_days_forecast_week5);
        mDaysForecastTvWeek6 = (TextView) view.findViewById(R.id.wea_days_forecast_week6);

        mDaysForecastTvDay2 = (TextView) view.findViewById(R.id.wea_days_forecast_day2);
        mDaysForecastTvDay3 = (TextView) view.findViewById(R.id.wea_days_forecast_day3);
        mDaysForecastTvDay4 = (TextView) view.findViewById(R.id.wea_days_forecast_day4);
        mDaysForecastTvDay5 = (TextView) view.findViewById(R.id.wea_days_forecast_day5);
        mDaysForecastTvDay6 = (TextView) view.findViewById(R.id.wea_days_forecast_day6);

        mDaysForecastWeaTypeDayIv2 = (ImageView) view.findViewById(R.id.wea_days_forecast_weather_day_iv2);
        mDaysForecastWeaTypeDayIv3 = (ImageView) view.findViewById(R.id.wea_days_forecast_weather_day_iv3);
        mDaysForecastWeaTypeDayIv4 = (ImageView) view.findViewById(R.id.wea_days_forecast_weather_day_iv4);
        mDaysForecastWeaTypeDayIv5 = (ImageView) view.findViewById(R.id.wea_days_forecast_weather_day_iv5);
        mDaysForecastWeaTypeDayIv6 = (ImageView) view.findViewById(R.id.wea_days_forecast_weather_day_iv6);

        mDaysForecastWeaTypeDayTv2 = (TextView) view.findViewById(R.id.wea_days_forecast_weather_day_tv2);
        mDaysForecastWeaTypeDayTv3 = (TextView) view.findViewById(R.id.wea_days_forecast_weather_day_tv3);
        mDaysForecastWeaTypeDayTv4 = (TextView) view.findViewById(R.id.wea_days_forecast_weather_day_tv4);
        mDaysForecastWeaTypeDayTv5 = (TextView) view.findViewById(R.id.wea_days_forecast_weather_day_tv5);
        mDaysForecastWeaTypeDayTv6 = (TextView) view.findViewById(R.id.wea_days_forecast_weather_day_tv6);

        mCharView = (LineChartViewDouble) view.findViewById(R.id.line_char);

        mDaysForecastWeaTypeNightIv2 = (ImageView) view.findViewById(R.id.wea_days_forecast_weather_night_iv2);
        mDaysForecastWeaTypeNightIv3 = (ImageView) view.findViewById(R.id.wea_days_forecast_weather_night_iv3);
        mDaysForecastWeaTypeNightIv4 = (ImageView) view.findViewById(R.id.wea_days_forecast_weather_night_iv4);
        mDaysForecastWeaTypeNightIv5 = (ImageView) view.findViewById(R.id.wea_days_forecast_weather_night_iv5);
        mDaysForecastWeaTypeNightIv6 = (ImageView) view.findViewById(R.id.wea_days_forecast_weather_night_iv6);

        mDaysForecastWeaTypeNightTv2 = (TextView) view.findViewById(R.id.wea_days_forecast_weather_night_tv2);
        mDaysForecastWeaTypeNightTv3 = (TextView) view.findViewById(R.id.wea_days_forecast_weather_night_tv3);
        mDaysForecastWeaTypeNightTv4 = (TextView) view.findViewById(R.id.wea_days_forecast_weather_night_tv4);
        mDaysForecastWeaTypeNightTv5 = (TextView) view.findViewById(R.id.wea_days_forecast_weather_night_tv5);
        mDaysForecastWeaTypeNightTv6 = (TextView) view.findViewById(R.id.wea_days_forecast_weather_night_tv6);

        mDaysForecastWindDirectionTv2 = (TextView) view.findViewById(R.id.wea_days_forecast_wind_direction_tv2);
        mDaysForecastWindDirectionTv3 = (TextView) view.findViewById(R.id.wea_days_forecast_wind_direction_tv3);
        mDaysForecastWindDirectionTv4 = (TextView) view.findViewById(R.id.wea_days_forecast_wind_direction_tv4);
        mDaysForecastWindDirectionTv5 = (TextView) view.findViewById(R.id.wea_days_forecast_wind_direction_tv5);
        mDaysForecastWindDirectionTv6 = (TextView) view.findViewById(R.id.wea_days_forecast_wind_direction_tv6);

        mDaysForecastWindPowerTv2 = (TextView) view.findViewById(R.id.wea_days_forecast_wind_power_tv2);
        mDaysForecastWindPowerTv3 = (TextView) view.findViewById(R.id.wea_days_forecast_wind_power_tv3);
        mDaysForecastWindPowerTv4 = (TextView) view.findViewById(R.id.wea_days_forecast_wind_power_tv4);
        mDaysForecastWindPowerTv5 = (TextView) view.findViewById(R.id.wea_days_forecast_wind_power_tv5);
        mDaysForecastWindPowerTv6 = (TextView) view.findViewById(R.id.wea_days_forecast_wind_power_tv6);

        mLifeIndexUmbrellaTv = (TextView) view.findViewById(R.id.wea_life_index_tv_umbrella);
        mLifeIndexUltravioletRaysTv = (TextView) view.findViewById(R.id.wea_life_index_tv_ultraviolet_rays);
        mLifeIndexDressTv = (TextView) view.findViewById(R.id.wea_life_tv_index_dress);
        mLifeIndexColdTv = (TextView) view.findViewById(R.id.wea_life_index_tv_cold);
        mLifeIndexMorningExerciseTv = (TextView) view.findViewById(R.id.wea_life_index_tv_morning_exercise);
        mLifeIndexSportTv = (TextView) view.findViewById(R.id.wea_life_index_tv_sport);
        mLifeIndexCarWashTv = (TextView) view.findViewById(R.id.wea_life_index_tv_car_wash);
        mLifeIndexAirCureTv = (TextView) view.findViewById(R.id.wea_life_index_tv_air_cure);

        // 雨伞指数控件
        RelativeLayout lifeIndexUmbrellaRlyt = (RelativeLayout) view.findViewById(R.id.wea_life_index_rlyt_umbrella);
        // 紫外线指数控件
        RelativeLayout lifeIndexUltravioletRaysRlyt = (RelativeLayout) view.findViewById(R.id.wea_life_index_rlyt_ultraviolet_rays);
        // 穿衣指数控件
        RelativeLayout lifeIndexDressRlyt = (RelativeLayout) view.findViewById(R.id.wea_life_index_rlyt_dress);
        // 感冒指数控件
        RelativeLayout lifeIndexColdRlyt = (RelativeLayout) view.findViewById(R.id.wea_life_index_rlyt_cold);
        // 晨练指数控件
        RelativeLayout lifeIndexMorningExerciseRlyt = (RelativeLayout) view.findViewById(R.id.wea_life_index_rlyt_morning_exercise);
        //  运动指数控件
        RelativeLayout lifeIndexSportRlyt = (RelativeLayout) view.findViewById(R.id.wea_life_index_rlyt_sport);
        // 洗车指数控件
        RelativeLayout lifeIndexCarWashRlyt = (RelativeLayout) view.findViewById(R.id.wea_life_index_rlyt_carwash);
        // 晾晒指数控件
        RelativeLayout lifeIndexAirCureRlyt = (RelativeLayout) view.findViewById(R.id.wea_life_index_rlyt_air_cure);

        //设置点击事件，弹出具体的详情
//        lifeIndexUmbrellaRlyt.setOnClickListener(this);
//        lifeIndexUltravioletRaysRlyt.setOnClickListener(this);
//        lifeIndexDressRlyt.setOnClickListener(this);
//        lifeIndexColdRlyt.setOnClickListener(this);
//        lifeIndexMorningExerciseRlyt.setOnClickListener(this);
//        lifeIndexSportRlyt.setOnClickListener(this);
//        lifeIndexCarWashRlyt.setOnClickListener(this);
//        lifeIndexAirCureRlyt.setOnClickListener(this);

        mDensity = getResources().getDisplayMetrics().density;
        mBlurDrawable = MyUtil.getWallPaperBlurDrawable(getActivity());
        mBackGround = (LinearLayout) view.findViewById(R.id.wea_background);

        NestedScrollView nestscroll = (NestedScrollView) view
                .findViewById(R.id.nestscroll);
        nestscroll.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                // scroll最大滚动距离（xxxh：2320）/密度（xxxh：3）/1.5  =  515
                mAlpha = Math.round(Math.round(scrollY / mDensity / 1.5));
                if (mAlpha > 255) {
                    mAlpha = 255;
                } else if (mAlpha < 0) {
                    mAlpha = 0;
                }
                // 设置模糊处理后drawable的透明度
                mBlurDrawable.setAlpha(mAlpha);
                // 设置背景
                //noinspection deprecation
//                ((WeatherActivity)getActivity()).getToolbar().setAlpha(mAlpha);
                mBackGround.setBackgroundDrawable(mBlurDrawable);
            }
        });

    }

}
